local skynet = require "skynet"
local socket = require "skynet.socket"
local log = require "sky_log"
local nn = require "sky_node"

local service_web_connect = {}

function service_web_connect.handler(fd, addr)
    --log.info("service_web_connect addr=", addr)
    local agent = skynet.newservice("service_web_agent")
    skynet.send(agent, "lua", fd, addr)
end

skynet.start(function()
    local node_name = skynet.getenv("node_name")
    local index = tonumber(nn[node_name]) 
    assert(index)
    local port = tonumber(index)
    local listen_fd = socket.listen("0.0.0.0", port)
	log.warning(string.format("Listen web port "..port.." protocol:%s ", "http/https"))
    socket.start(listen_fd, service_web_connect.handler)

end)
